package org.huawei260.shousi;

/**
 * @Auther: qingle
 * @Date: 2024/10/31-16:10
 * @Description:
 * @version: 1.0
 */
public class OD_1_交换一次字符串 {

	public static void main(String[] args) {
		String s = "bank";
		String t = "kanb";
		System.out.println(canBeEqualByOneSwap(s, t));
	}

	public static boolean canBeEqualByOneSwap(String s1, String s2) {
		if (s1.length() != s2.length()) {
			return false;
		}

		if (s1.equals(s2)) {
			return true;
		}

		int first = -1, second = -1;
		for (int i = 0; i < s1.length(); i++) {
			if (s1.charAt(i) != s2.charAt(i)) {
				if (first == -1) {
					first = i;
				} else if (second == -1) {
					second = i;
				} else {
					return false;
				}
			}
		}

		return (second != -1 && s1.charAt(first) == s2.charAt(second) && s1.charAt(second) == s2.charAt(first));
	}


}
